package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.BGreenCertificate;
import com.isdepci.project.carbon.domain.param.WeatherDataExcel;
import com.isdepci.project.carbon.service.IBGreenCertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购买绿证Controller
 *
 * @author isdepci
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/green/certificate")
public class BGreenCertificateController extends BaseController
{
    @Autowired
    private IBGreenCertificateService bGreenCertificateService;


    /**
     * 购买绿证碳汇计算
     */
    @GetMapping("/calGreenCertificate")
    public AjaxResult calGreenCertificate(@RequestParam Long projectId) {
        return bGreenCertificateService.calGreenCertificate(projectId);
    }


    /**
     * 查询购买绿证列表
     */
    //   @PreAuthorize("@ss.hasPermi('green:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(BGreenCertificate bGreenCertificate)
    {
        startPage();
        List<BGreenCertificate> list = bGreenCertificateService.selectBGreenCertificateList(bGreenCertificate);
        return getDataTable(list);
    }

    /**
     * 导出购买绿证列表
     */
    //   @PreAuthorize("@ss.hasPermi('green:certificate:export')")
    @Log(title = "购买绿证", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BGreenCertificate bGreenCertificate)
    {
        List<BGreenCertificate> list = bGreenCertificateService.selectBGreenCertificateList(bGreenCertificate);
        ExcelUtil<BGreenCertificate> util = new ExcelUtil<BGreenCertificate>(BGreenCertificate.class);
        return util.exportExcel(list, "certificate");
    }

    /**
     * 上传保存数据
     * @param excel
     * @return
     */
    @PostMapping("/changeData")
    public AjaxResult changeDataByProjectId(@RequestBody WeatherDataExcel excel) {
        return bGreenCertificateService.changeDataByProjectId(excel);
    }


    /**
     * 获取购买绿证详细信息
     */
    //   @PreAuthorize("@ss.hasPermi('green:certificate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bGreenCertificateService.selectBGreenCertificateById(id));
    }

    /**
     * 新增购买绿证
     */
    //   @PreAuthorize("@ss.hasPermi('green:certificate:add')")
    @Log(title = "购买绿证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BGreenCertificate bGreenCertificate)
    {
        return toAjax(bGreenCertificateService.insertBGreenCertificate(bGreenCertificate));
    }

    /**
     * 修改购买绿证
     */
    //   @PreAuthorize("@ss.hasPermi('green:certificate:edit')")
    @Log(title = "购买绿证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BGreenCertificate bGreenCertificate)
    {
        return toAjax(bGreenCertificateService.updateBGreenCertificate(bGreenCertificate));
    }

    /**
     * 删除购买绿证
     */
    //   @PreAuthorize("@ss.hasPermi('green:certificate:remove')")
    @Log(title = "购买绿证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bGreenCertificateService.deleteBGreenCertificateByIds(ids));
    }
}
